<?php
/*
	This file is part of UserMgmt.

	Author: 
*/
?>
<div class="umtop">
	<?php echo $this->Session->flash(); ?>
	<div class="um_box_up"></div>
	<div class="um_box_mid">
		<div class="um_box_mid_content">
			<div class="um_box_mid_content_top">
				<span class="umstyle1"><?php echo __('All Users'); ?></span>
				<div style="clear:both"></div>
			</div>
			<div class="umhr"></div>
			<div class="um_box_mid_content_mid" id="index">
				<table cellspacing="0" cellpadding="0" width="100%" border="0" >
					<thead>
						<tr>
							<th><?php echo __('SL');?></th>
							<th><?php echo $this->Paginator->sort('first_name', 'Name', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'))?></th>
							<th><?php echo $this->Paginator->sort('username','Username', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));?></th>
							<th><?php echo $this->Paginator->sort('email','Email', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));?></th>
							<th><?php echo $this->Paginator->sort('user_group_id','Group',array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));?></th>
							<th><?php echo $this->Paginator->sort('active','Status', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));?></th>
							<th><?php echo $this->Paginator->sort('created','Created', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));?></th>
							<th><?php echo __('Action');?></th>
						</tr>
					</thead>
					<tbody>
			<?php       if (!empty($users)) {
							$sl=0;
							foreach ($users as $row) {
								$sl++;
								echo "<tr>";
								echo "<td>".$sl."</td>";
								echo "<td>".h($row['User']['first_name'])." ".h($row['User']['last_name'])."</td>";
								echo "<td>".h($row['User']['username'])."</td>";
								echo "<td>".h($row['User']['email'])."</td>";
								echo "<td>".h($row['UserGroup']['name'])."</td>";
								echo "<td>";
								if ($row['User']['active']==1) {
									echo "Active";
								} else {
									echo "Inactive";
								}
								echo"</td>";
								echo "<td>".date('d-M-Y',strtotime($row['User']['created']))."</td>";
								echo "<td>";
								
									echo "<span class='icon'>";
									echo $this->Ajax->link(
										$this->Html->image(SITE_URL.'/img/view.png', array('boder' => '0', 'alt' => 'View', 'title' => 'View')), 
										'/viewUser/'.$row['User']['id'], 
										array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
									);
									echo "</span>";
									
									echo "<span class='icon'>";
									echo $this->Ajax->link(
										$this->Html->image(SITE_URL.'/img/edit.png', array('boder' => '0', 'alt' => 'Edit User', 'title' => 'Edit User')), 
										'/editUser/'.$row['User']['id'], 
										array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
									);
									echo "</span>";
									
									echo "<span class='icon'>";
									echo $this->Ajax->link(
										$this->Html->image(SITE_URL.'/img/password.png', array('boder' => '0', 'alt' => 'Change User Password', 'title' => 'Change User Password')), 
										'/changeUserPassword/'.$row['User']['id'], 
										array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
									);
									echo "</span>";
									
									if ($row['User']['active']==0) {
										echo "<span class='icon'>";
										echo $this->Ajax->link(
											$this->Html->image(SITE_URL.'/img/approve.png', array('boder' => '0', 'alt' => 'Make Active', 'title' => 'Make Active')),
											'/users/makeActive/'.$row['User']['id'], 
											array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
										);
										echo "</span>";
									}
									if ($row['User']['id']!=1 && $row['User']['username']!='Admin') {
										echo "<span class='icon'>";
										echo $this->Ajax->link(
											$this->Html->image(SITE_URL.'/img/delete.png',array('boder' => '0', 'alt' => 'Delete', 'title' => 'Delete')),
											'/deleteUser/'.$row['User']['id'],
											array('update' => 'MainContent','indicator' => 'loading', 'type' => 'POST', 'escape' => false),
											'Are you sure you want to delete this user?');
										echo "</span>";
									}
								echo "</td>";
								echo "</tr>";
							}
						} else {
							echo "<tr><td colspan=10><br/><br/>No Data</td></tr>";
						} ?>
					</tbody>
				</table>
				<?php
				echo "<div class='box_pagging'>";
					echo "<div class='box_pagging_info box_pagging_info_boder'>";
						echo $this->Paginator->counter('Total of record {:count}, starting on record {:start}, ending on {:end}');
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->first("<< First", array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->prev(' << ' . __('previous'),array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'), null, array('class' => 'prev disabled'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->numbers(array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->next(__('next'). ' >>', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'), null, array('class' => 'next disabled'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->last("Last >>", array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));
					echo "</div>";
					echo "<div class='box_pagging_info box_pagging_info_boder'>";
						echo $this->Paginator->counter('Number of record {:page} of {:pages}');
					echo "</div>";
				echo "</div>";
				?>
			</div>
		</div>
	</div>
	<div class="um_box_down"></div>
</div>